//
//  TZMainTabBar.swift
//  weibo_Swift
//
//  Created by 涂真 on 15/12/15.
//  Copyright © 2015年 涂真. All rights reserved.
//

import UIKit

class TZMainTabBar: UITabBar {
    //MARK: - 定义tabbar视图的控件个数
    let count = 5
    override func layoutSubviews() {
         super.layoutSubviews()
        var index = 0
        let width = bounds.size.width/CGFloat(count)
        let itemFrame = CGRect(x: 0, y: 0, width: width, height: bounds.size.height)
        for subview in subviews{
            
            if subview is UIControl && !(subview is UIButton){
                subview.frame = CGRectOffset(itemFrame, CGFloat(index)*width, 0)
                index += index==1 ? 2:1
            
            }
            
        }
        centerItem.frame = CGRectOffset(itemFrame, width*2, 0)
       
    }
    
    //MARK: - 懒加载
    lazy var centerItem: UIButton = {
    let button = UIButton()
        self.addSubview(button)
        button.setBackgroundImage(UIImage(named: "tabbar_compose_button"), forState: UIControlState.Normal)
        button.setBackgroundImage(UIImage(named: "tabbar_compose_button"+"_highlighted"), forState: UIControlState.Highlighted)
        button.setImage(UIImage(named: "tabbar_compose_icon_add"), forState: UIControlState.Normal)
        button.setImage(UIImage(named: "tabbar_compose_icon_add"+"_highlighted"), forState: UIControlState.Highlighted)

    return button
    }()
    
//添加中间的按钮
//    func addCenterItem(backgroundImageName:String,imageName:String) ->UIButton{
//        //    _highlighted
//        let centerItem = UIButton()
//        addSubview(centerItem)
//        centerItem.setBackgroundImage(UIImage(named: backgroundImageName), forState: UIControlState.Normal)
//        centerItem.setBackgroundImage(UIImage(named: backgroundImageName+"_highlighted"), forState: UIControlState.Highlighted)
//        centerItem.setImage(UIImage(named: imageName), forState: UIControlState.Normal)
//        centerItem.setImage(UIImage(named: imageName+"_highlighted"), forState: UIControlState.Highlighted)
//        
//        return centerItem
//    }
    
}
